/**************************************************************************************************
 * light library                                                                                   *
 * Copyright © 2012 David Kretzmer                                                                *
 *                                                                                                *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software  *
 * and associated documentation files (the "Software"), to deal in the Software without           *
 * restriction,including without limitation the rights to use, copy, modify, merge, publish,      *
 * distribute,sublicense, and/or sell copies of the Software, and to permit persons to whom the   *
 * Software is furnished to do so, subject to the following conditions:                           *
 *                                                                                                *
 * The above copyright notice and this permission notice shall be included in all copies or       *
 * substantial portions of the Software.                                                          *
 *                                                                                                *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING  *
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND     *
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.        *
 *                                                                                                *
 *************************************************************************************************/

#pragma once

#include "light/utility/non_copyable.hpp"
#include "light/io/internal/file_base.hpp"


namespace light
{
namespace io
{
namespace internal
{
	class file_base : private non_copyable
	{
	public:
		// Constructor. Opens a file
		file_base(utf8_unit const *filename, access acc);

		// Destructor. Closes the file
		~file_base();

		// Opens a file. If you are only reading the file then it must already exist
		void open(utf8_unit const *filename, access acc);

		// Closes the file
		void close();

		// Writes 'num_bytes' from 'data' to the file. Returns the number of bytes actually written
		size_t write(void const *data, size_t num_bytes);

		// Reads 'num_bytes' from the file to 'data'. Returns the number of bytes actually read
		size_t read(void *data, size_t num_bytes);

		// Sets the read/write offset relative from 'pos'. Returns the offset from tzhe beginning of the file
		uint8 seek(uint8 offset, seek_pos pos);

		// Gets the current read/write offset
		uint8 tell() const;

		// Gets the size of the file
		uint8 size() const;

		// Gets the file descriptor
		int descriptor() const { return m_descriptor; }

	private:
		int m_descriptor;
	};

} // namespace: internal
} // namespace: io
} // namespace: light
